<?php

namespace App\Admin\Forms;

use App\Helpers\Lib\RedisService;
use App\Models\TongUser;
use App\Models\TongUserProfit;
use App\Models\TongUserWithdrawal;
use Dcat\Admin\Traits\LazyWidget;
use Dcat\Admin\Widgets\Form;
use Illuminate\Support\Facades\DB;

class UpdateLeader extends Form
{
    use LazyWidget;
    /**
     * Handle the form request.
     *
     * @param array $input
     *
     * @return mixed
     */
    public function handle(array $input)
    {
        //dump($input);

        // return $this->response()->error('Your error message.');

        TongUser::query()->where('id',$input['id'])->update(['is_leader'=>$input['is_leader']]);
        //获取用户信息
//        $user_info = TongUser::query()->where('id',$input['id'])->first();
//        $old = ['id'=>$user_info['id'],'p_id'=>$user_info['p_id'],'identity_id'=>$user_info['identity_id'],'is_real_store'=>$user_info['is_real_store']];
//        ksort($old);
//        $new_val = ['id'=>$user_info['id'],'p_id'=>$user_info['p_id'],'identity_id'=>$user_info['identity_id'],'is_real_store'=>$input['is_real_store']];
//        ksort($new_val);
//        //修改用户的身份
//        RedisService::sUpdate($old,$new_val);
        //updateUserRealStore($input['id'],$input['is_real_store']);
        return $this
            ->response()
            ->success('设置成功')
            ->refresh();
    }

    /**
     * Build a form here.
     */
    public function form()
    {
        $this->hidden('id','id')->required();
        //$this->select('money','充值金额')->required();
        $this->radio('is_leader','领导人')->options([1 => '领导人', 0=>'非领导']);
    }

    /**
     * The data of the form.
     *
     * @return array
     */
    public function default()
    {
        return [
            'id'=>$this->payload['id'] ?? null,
            'is_leader'  => 0,
        ];
    }
}
